package com.baozun.util;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * @Title:
 * @Company:宝尊电子商务有限公司
 * @Author:万世极缘
 * @Since:2014-12-28
 * @Copyright:Copyright (c) 2014
 * @ModifyDate:2014-12-28
 * @Version:1.1.0
 */
public class AjaxUtil {

    /**
     * 获得response中的writer
     * 
     * @param request
     * @param response
     * @return
     */
    public static PrintWriter getWriter(HttpServletRequest request, HttpServletResponse response) {
        PrintWriter out = null;
        try {
            request.setCharacterEncoding("utf-8");
            response.setContentType("text/html;charset=utf-8");
            out = response.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return out;
    }

    /**
     * 设计请求响应的编码规则
     * @param request
     * @param response
     * @param encode
     * @Description:
     */
    public static void setCharset(HttpServletRequest request, HttpServletResponse response, String encode) {
        // TODO Auto-generated method stub
        try {
            request.setCharacterEncoding(encode);
            response.setContentType("text/html;charset=" + encode);
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}
